﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Web.UI;

namespace Eugenhome.Atrium.Bookmark.Web
{
    /// <summary>
    /// 
    /// </summary>
    public partial class BookmarkView : System.Web.UI.Page
    {
        /// <summary></summary>
        private BookmarkCollection _bc;

        /// <summary></summary>
        private Login _login = new Login();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            _login.Check();

            _bc = new BookmarkCollection();

            _bc.DataFullFileName = Server.MapPath("bookmark.xml");
            _bc.Load();

            //DynDNSController ddc = new DynDNSController(Server.MapPath(""), "hjas34pdoih38alerm95nebraa");
            //ddc.DynBookmarkCollection.GetBookmarks().ForEach(item => _bc.Add(item));

            if (!IsPostBack)
            {
                string savedSelectedLabel = _bc.SelectedLabel;

                cbLabels.DataSource = _bc.LabelList;
                cbLabels.DataBind();
                cbLabels.SelectedValue = savedSelectedLabel;

                cbLabels_SelectedIndexChanged(null, null);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cbLabels_SelectedIndexChanged(object sender, EventArgs e)
        {
            _bc.SetSelectedLabel(cbLabels.SelectedItem.ToString());

            repBookmarks.DataSource = _bc.GetBookmarks().Select(item => new BookmarkItem(item)).ToList();
            repBookmarks.DataBind();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSetFavorit_Click(object sender, ImageClickEventArgs e)
        {
            cbLabels.SelectedIndex = 1;
            cbLabels_SelectedIndexChanged(null, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSetHaushalt_Click(object sender, ImageClickEventArgs e)
        {
            cbLabels.SelectedIndex = 2;
            cbLabels_SelectedIndexChanged(null, null);
        }
    }
}